package cc.wsyw126.java.interview.toutiao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        ArrayList<Node> nodes = new ArrayList<>();
        while (n-- > 0) {
            String s = sc.nextLine();
            String[] split = s.split(" ");
            Node node = new Node();
            node.setX(Integer.parseInt(split[0]));
            node.setY(Integer.parseInt(split[1]));
            nodes.add(node);

        }
        Collections.sort(nodes, (o1, o2) -> o1.getX() - o2.getX());
        ArrayList<Node> result = new ArrayList<>();
        int size = nodes.size();
        int max = -1;
        for (int i = size - 1; i >= 0; i--) {
            int y = nodes.get(i).getY();
            if (y > max) {
                result.add(nodes.get(i));
                max = y;
            }
        }
        int size1 = result.size();
        for (int i = size1 - 1; i >= 0; i--) {
            System.out.println(result.get(i).getX() + " " + result.get(i).getY());
        }
    }

    static class Node {
        private int x;
        private int y;

        public int getX() {
            return x;
        }

        public void setX(int x) {
            this.x = x;
        }

        public int getY() {
            return y;
        }

        public void setY(int y) {
            this.y = y;
        }

        @Override
        public String toString() {
            return "Node{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }
    }
}
